﻿Create Procedure [dbo].[accounts_register_user]
-- --------------------------------------------------------------------------------- 
-- Procedure Name: accounts_register_user
--
-- Description: Creates a registration request
--
--
--
-- Version  Date          Author           Description
-- ---------------------------------------------------------------------------------
--  1       03-Mar-2012   The Collective   Created procedure
-- 
--
--
--
-- ---------------------------------------------------------------------------------
-- ---------------------------------------------------------------------------------
(@first_name as varchar(50),
@last_name as varchar(50),
@phone_number as varchar(30),
@organisation as varchar(50),
@email as varchar(255),
@passwordencrypt as varchar(255),
@returncode as int output,
@returnmessage as varchar(200) output )
AS
BEGIN

    set nocount on

	Declare @NumofRows int;

	-- Do the insert
	Insert into Accounts_Registration_Requests (user_GUID, first_name, last_name, phone_number, organisation, email, passwordencrypt, datetimecreated)
	values(newid(), @first_name, @last_name, @phone_number, @organisation, @email, @passwordencrypt, getdate());

	-- Get the row count of records inserted
	set @NumofRows = @@RowCount;

	if (@NumofRows = 1)
	  Begin
	      Set @returncode = 0;
          Set @returnmessage = 'Successfully registered.'; 
	  end;
    else
	  Begin
	      Set @returncode = 1;
          Set @returnmessage = 'Registration failed.'; 
	  end;
	      
    set nocount off
    
    Return 0;

END;